<?php
class createClient extends client {
	function __construct() {
		parent::__construct();
		$this->data['usuarios'] = array();
		$this->data['clientes'] = array();
	}

	public function insert($tabla) {
		$arrDatos = $this->data[$tabla];
		$arr_keys = array_keys($arrDatos);
		$values = "";
		$keys = "";
		$query = "INSERT INTO ".$tabla;
		for ($i = 0; $i < count($arr_keys);$i++) {
			$keys .=$arr_keys[$i].",";
			if (is_string($arrDatos[$arr_keys[$i]])) {	$values .= "'".$arrDatos[$arr_keys[$i]]."',"; }
			else { $values .= $arrDatos[$arr_keys[$i]].","; }
		}
		$keys = substr($keys,0,strlen($keys)-1);
		$values = substr($values,0,strlen($values)-1);
		$query .= "(".$keys.") VALUES (".$values.");";
		try {
			mysql_query($query);
			if (1000 < mysql_errno() && mysql_errno() < 2056) throw new Exception("Error al intentar dar de alta el nuevo cliente.");
		} catch (Exception $e) {
			echo mysql_errno(). " : " .mysql_error();
			exit();
		}
		return mysql_insert_id();
	}

	public function getRoles() {
		$arr_result = array();
		$query = 'SELECT nombre,id FROM roles WHERE (fk_origen = 0) AND (estado = 1);';
		$results = mysql_query($query) or die(mysql_error());
		$i = 0;
		while ($reg = mysql_fetch_array($results)) {
			$arr_result[$i]['nombre'] = $reg['nombre'];
			$arr_result[$i]['id'] = $reg['id'];
			$i++;
		}
		return $arr_result;
	}
}
?>